package com.jinke.uang.view;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

/**
 * @author lixiaonan
 * 功能描述: 产品间距的
 * 时 间： 2019/4/2 下午11:16
 */
public class SpaceItemDecoration extends RecyclerView.ItemDecoration {

    private int space;

    public SpaceItemDecoration(int space) {
        this.space = space;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
                               RecyclerView.State state) {

        outRect.bottom = space;
        //由于每行都只有3个，所以第一个都是3的倍数，把左边距设为0
        if (parent.getChildLayoutPosition(view) % 3 == 0) {
            outRect.right = space / 2;
        }
        if (parent.getChildLayoutPosition(view) % 3 == 1) {
            outRect.left = space / 2;
            outRect.right = space / 2;
        }
        if (parent.getChildLayoutPosition(view) % 3 == 2) {
            outRect.left = space / 2;
        }
    }

}